<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <style type="text/css">
        body, html {
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }

        #allmap {
            height: 500px;
            width: 100%;
            height: 95%;
        }

        #r-result, #r-result table {
            width: 100%;
        }
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=UzpZ9A94pysSfj013URfjCfeUKjMv52F"></script>
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
    <script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>

    <title>根据起终点名称驾车导航</title>
</head>
<body>
<div id="allmap"></div>
    起始点<input id ="start1" type="text">
    目的点<input id ="end1" type="text">
<div id="driving_way">
    <!--<button type="button" onclick="getItem()"></button><br/>-->
    <select>
        <option value="0">最少时间</option>
        <option value="1">最短距离</option>
        <option value="2">避开高速</option>
    </select>

    <input type="button" id="result" value="查询"/>

</div>
<div id="r-result"></div>

</body>
</html>
<script type="text/javascript">


    // var start ="";
    // var end ="";
    // $.get('/cargo/shippingOrder/gangkou.do').done(function (data) {
    //    start= data.portOfLoading;
    //    end= data.portOfDischarge;
    //
    // }
    // 百度地图API功能
    var map = new BMap.Map("allmap");
    map.enableScrollWheelZoom(true);
    map.addControl(new BMap.MapTypeControl());
    // var start ="北京西";
    // var end ="上海站";
    // var start = $.('#start1').value;
    // var end = $.('#end1').value;
    // var start = start1.val();
    // var end =end1.val();

    // function GetQueryString1(name)
    // {
    //     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    //     var r = window.location.search.substr(1).match(reg);//search,查询？后面的参数，并匹配正则
    //     if(r!=null)return  unescape(r[2]); return null;
    // }




    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r != null) return decodeURI(r[2]);
        return null;
    }





    $('#start1').blur(function(){
    start =$(this).val()
    // alert(start)
});
    $('#end1').blur(function(){
    end =$(this).val()
});
    start = (GetQueryString("start1"));
    // alert(start);
    end = (GetQueryString("end1"));
    // alert(end);

    // function getItem() {
    //     var start =  document.getElementsByName("start").value;
    //     var end =  document.getElementById("end").value
    //     alert.(start);
    // };
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
    // setInterval(goWay,800); // 0.8秒画一次线
    //三种驾车策略：最少时间，最短距离，避开高速
    var routePolicy = [BMAP_DRIVING_POLICY_LEAST_TIME, BMAP_DRIVING_POLICY_LEAST_DISTANCE, BMAP_DRIVING_POLICY_AVOID_HIGHWAYS];
    $("#result").click(function () {
        map.clearOverlays();
        var i = $("#driving_way select").val();
        search(start, end, routePolicy[i]);

        function search(start, end, route) {
            var driving = new BMap.DrivingRoute(map, {renderOptions: {map: map, autoViewport: true}, policy: route});
            driving.search(start, end);
        }
    });

</script>

